﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Model.Common;

namespace Model.Catalog
{
    public class Product
    {
        public Product()
        {
            //
            // TODO: Add constructor logic here
            //
        }


        //------------------------------------------------------------------------------------------//
        //Get All Product
        public static DataTable GetAllProducts(string OrderBy)
        {
            try
            {
                string[] paramName = { "@OrderBy" };
                object[] paramValue = { OrderBy };
                return DataAccess.GetData(paramName, paramValue, "GetAllProducts");
            }
            catch
            {
                return null;
            }
        }

        //-----------------------------------------------------------------------//
        //Get Products by category ID
        public static DataTable GetProductByCategoryId(string CategoryId, string OrderBy, int PageIndex, int PageSize)
        {
            DataTable dt;
            try
            {
                string[] paramName = { "@CategoryId", "@OrderBy" ,"@PageIndex","@PageSize" };
                object[] paramValue = { CategoryId, OrderBy, PageIndex,PageSize };
                dt = DataAccess.GetData(paramName, paramValue, "GetProductByCategoryId");
                return dt;
            }
            catch
            {
                return null;
            }
        }



        //-----------------------------------------------------------------------//
        //Get Product detail by Product ID
        public static DataTable GetProductDetailByProductId(string ProductId)
        {
            DataTable dt;
            try
            {
                string[] paramName = { "@ProductId" };
                object[] paramValue = { ProductId };
                dt = DataAccess.GetData(paramName, paramValue, "GetProductDetailByProductID");
                return dt;
            }
            catch
            {
                return null;
            }
        }

        public static DataTable GetReviewByProductId(string ProductId,int PageIndex,int PageSize)
        {
            DataTable dt;
            try
            {
                string[] paramName = { "@ProductId", "@PageIndex", "@PageSize" };
                object[] paramValue = { ProductId,PageIndex,PageSize };
                dt = DataAccess.GetData(paramName, paramValue, "GetReviewByProductId");
                return dt;
            }
            catch
            {
                return null;
            }
        }

        //Add new Review
        public static int AddReview(string ProductId,string Author,string Email,string Content)
        {
            string[] paramName = { "@ProductId","@Author","@Email","@Content" };
            object[] paramValue = { ProductId, Author,Email,Content };
            try
            {
                return DataAccess.InsertUpdate(paramName,paramValue,"AddReview");
            }
            catch
            {
                return 0;            
            }
        }

        //Get product relate
        public static DataTable GetProductsRelate(string ProductId)
        {
            DataTable dt;
            try
            {
                string[] paramName = { "@ProductId" };
                object[] paramValue = { ProductId };
                dt = DataAccess.GetData(paramName, paramValue, "GetProductsRelate");
                return dt;
            }
            catch
            {
                return null;
            }
        }

        //Get Rows Review by ProductId
        public static DataTable GetCountReviewByProductId(string ProductId)
        {
            DataTable dt;
            try
            {
                string[] paramName = { "@ProductId" };
                object[] paramValue = { ProductId };
                dt = DataAccess.GetData(paramName, paramValue, "GetCountReviewByProductId");
                return dt;
            }
            catch
            {
                return null;
            }
        }


        //Get Rows Products by CategoryId
        public static DataTable GetCountProductsByCategoryId(string CategoryId)
        {
            DataTable dt;
            try
            {
                string[] paramName = { "@CategoryId" };
                object[] paramValue = { CategoryId };
                dt = DataAccess.GetData(paramName, paramValue, "GetCountProductsByCategoryId");
                return dt;
            }
            catch
            {
                return null;
            }
        }

        //
        //-------------------------------------------------
        //--Get product best sell
        public static DataTable GetProductsBestSell()
        {
            DataTable dt;
            try
            {
                dt = DataAccess.GetData(null, null, "GetProductsBestSell");
                return dt;
            }
            catch
            {
                return null;
            }
        }
        
    }
}
